package se.webbzon.boltzmann.effect;

import se.webbzon.boltzmann.game.character.AbstractCharacter;
import se.webbzon.oschi01.worldarea.WorldArea;

public class CharacterSpinningEffect extends CharacterEffect {
	
	// The number of turns performed by this effect
	private final double nrOfTurns;
	
	/*============================================================
	Constructors
	============================================================*/
	
	/** Creates a character spinning effect which spins the given character
	 * during the given duration (in number of steps). The character will spin
	 * a total amount of 2*pi radians during the given time of the effect. **/
	public CharacterSpinningEffect(AbstractCharacter character, int duration) {
		this(character,duration,1);
	}
	
	/** Creates a character spinning effect which spins the given character
	 * during the given duration (in number of steps). **/
	public CharacterSpinningEffect(AbstractCharacter character, int duration, double nrOfTurns) {
		super(character,duration);
		this.nrOfTurns = nrOfTurns;
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public void onEffectBegin(WorldArea world) {};
	
	@Override public void onEffectStep(WorldArea world) {
		final double t = getDuration() / (double) getStartupDuration();
		getCharacter().setRotation(	0, 
									1, 
									0, 
									nrOfTurns * t * 2 * Math.PI);
	}
	
	@Override public void onEffectEnd(WorldArea world) {
		getCharacter().setRotation(0, 1, 0, 0);
	}

}
